package com.dq.Week3.day11;

import java.sql.Connection;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class CollectionDemo {
    public static void main(String[] args) {

        Collection<Integer> integers = new ArrayList<>();
        boolean add = integers.add(10);
        System.out.println(add);
        System.out.println(integers.add(12));
        System.out.println(integers.add(4));
        System.out.println(integers.add(4));

        Collection<Integer> c2 = new ArrayList<>();
        c2.add(12);
        c2.add(15);
        boolean b =  integers.addAll(c2);
//        System.out.println(integers);
//        integers.clear();
//        System.out.println(integers);
//        boolean b2 =integers.contains(12);
//        System.out.println(b2);
//        System.out.println(integers);

        for (Integer integer:integers)
        {
            System.out.println(integer);
        }
        System.out.println("----------------------------------");
        integers.forEach(c-> System.out.println(c));
        System.out.println("----------------------------------");
        //使用iterator方法去遍历集合
        Iterator<Integer> iterator = integers.iterator();

        //如果迭代器中还有可以访问的元素，那么iterator.hasNext（）
        //返回true
        while (iterator.hasNext())
        {
            Integer next = iterator.next();
            System.out.println(next);

        }//        boolean b3 = iterator.hasNext();
//        System.out.println(b3);
//        Integer next = iterator.next();
//        System.out.println(next);
    }
}
